﻿using Sharp.Infrastructure.WebApiClient;
using Sharp.Portal.Mvc;
using Sharp.ServiceContracts;
using System.Web.Mvc;
using Sharp.WebBooter.Areas.Workflow.Models;

// ReSharper disable Mvc.ViewNotResolved

namespace Sharp.WebBooter.Areas.Workflow.Controllers
{
    [Authorize]
    [AutomaticTemplate]
    public class TaskController : SharpController
    {
        /// <summary>
        /// 待处理
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View(new TaskIndexModel()
            {
                PageTitle="待处理"
            });
        }
        /// <summary>
        /// 已完成
        /// </summary>
        /// <returns></returns>
        public ActionResult Completed()
        {
            return View(new TaskIndexModel()
            {
                PageTitle = "已完成",
                StoreUrlAction = "GetCompletedPaged"
            });
        }
        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ActionResult GetPaged(DataTableParameter parameters)
        {
            using (var proxy = new WebApiClientServiceProxy<IWorkflowService>())
            { 
                var pageInfo = proxy.Channel.GetReadyTasksPaged(parameters.ToPagingFeature());

                return this.Store(pageInfo);
            }
        }

        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ActionResult GetCompletedPaged(DataTableParameter parameters)
        {
            using (var proxy = new WebApiClientServiceProxy<IWorkflowService>())
            {
                var pf = parameters.ToPagingFeature();

                var pageInfo = proxy.Channel.GetCompletedTasksPaged(pf);

                return this.Store(pageInfo);
            }
        }

    }
}